package top.kaoshanji.p2chapters.mapper;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.kaoshanji.p2chapters.model.SysRole;
import top.kaoshanji.p2chapters.model.SysRole1;

import java.util.List;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/12 18:09
 */
public interface RoleMapper {

    /**
     * 代码清单-p2chapters-149页a：获取所有角色和对应的权限信息
     * @return List
     */
    List<SysRole> selectAllRoleAndPrivileges();

    /**
     * 代码清单-p2chapters-157页a：根据用户id获取用户的角色信息
     * @param userId 用户id
     * @return 角色集合
     */
    List<SysRole> selectRoleByUserIdChoose(Long userId);


    @Select({"select id,role_name roleName, enabled, create_by createBy, create_time createTime",
            "from sys_role",
            "where id = #{id}"})
    SysRole selectById(Long id);

    @Update({"update sys_role",
            "set role_name = #{roleName},",
            "enabled = #{enabled},",
            "create_by = #{createBy},",
            "create_time = #{createTime, jdbcType=TIMESTAMP}",
            "where id = #{id}"
    })
    int updateById(SysRole sysRole);

    @Select({"select id,role_name roleName, enabled, create_by createBy, create_time createTime",
            "from sys_role",
            "where id = #{id}"})
    SysRole1 selectById1(Long id);

    @Update({"update sys_role",
            "set role_name = #{roleName},",
            "enabled = #{enabled},",
            "create_by = #{createBy},",
            "create_time = #{createTime, jdbcType=TIMESTAMP}",
            "where id = #{id}"
    })
    int updateById1(SysRole1 sysRole);



}
